rexpect
Spawn, control, and respond to expected patterns of child applications and processes, enabling the automation of interactions and testing. Components include:
- session: start a new process and interact with it; primary module of rexpect.
- reader: non-blocking reader, which supports waiting for strings, regex, and EOF.
- process: spawn a process in a pty.
The goal is to offer a similar set of functionality as pexpect.
Examples
For more examples, check the examples directory.
Basic usage
Add this to your Cargo.toml
[]
= "0.3"
Simple example for interacting via ftp:
extern crate rexpect;
use spawn;
use *;
Example with bash and reading from programs
extern crate rexpect;
use spawn_bash;
use *;
Example with bash and job control
One frequent bitfall with sending ctrl-c and friends is that you need to somehow ensure that the program has fully loaded, otherwise the ctrl-* goes into nirvana. There are two functions to ensure that:
execute
where you need to provide a match string which is present on stdout/stderr when the program is readywait_for_prompt
which waits until the prompt is shown again
extern crate rexpect;
use spawn_bash;
use *;
Project Status
Rexpect covers more or less the features of pexpect. If you miss anything I'm happy to receive PRs or also Issue requests of course.
The tests cover most of the aspects and it should run out of the box for rust stable, beta and nightly on both Linux or Mac.
Design decisions
- use error handling of error-chain
- use nix (and avoid libc wherever possible) to keep the code safe and clean
- sadly,
expect
is used in rust too prominently to unwrapOption
s andResult
s, useexp_*
instead
Licensed under MIT License